<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>中联众鑫建筑机械</title>
<link rel="stylesheet" media="all" type="text/css" href="admin.css" />
<script type="text/javascript" charset="utf-8" src="../ueditor/third-party/jquery-1.10.2.min.js"> </script>
<script type="text/javascript">
	function deleteNew(id) {
		$.ajax({
			type : "POST",
			url : "new_action.php",
			data : {id : id, act : "delete"},
			success : function(data) {
				if ("success" == data) {
					location.href = "new_list.php";
				} else {
					alert(data);
				}
			},
			error : function(data) {
				alert(data);
			}
		});
	}

	function editNew(id) {
		location.href = "new_edit.php?id=" + id;
	}
</script>
</head>
<body>
<div class="center">
	<?php include 'top.php';
			include '../business/dao/BaseDataAccess.php';
			include '../business/dao/NewsAccess.php';
			ini_set('display_errors',1);
			date_default_timezone_set("Asia/Shanghai");
			if (isset($_GET["pageNo"])) {
				$pageNo = $_GET["pageNo"];
			} else {
				$pageNo = 1;
			}
			$newsDao = new NewsDao();
			$page = new Page();
			$page->setPageSize(20);
			$page->setPageNo($pageNo);
			$newsDao->getNews($page);
			$data = $page->getData();
	?>
	<div class="box centent">
		<div class="right">
			<div class="title">新闻维护</div>
			<div class="datatable">
				<div style="height:365px;">
				<table width="100%" border="0" cellpadding="5" cellSpacing="5" >
					<thead>
						<tr>
							<th>标题</th>
							<th>作者</th>
							<th>发布日期</th>
							<th></th>
							<th></th>
						</tr>
					</thead>
					<tbody>
						<?php 
						for ($i = 0; $i < count($data); $i++) {
							$new = $data[$i]
						?>
						<tr>
							<td><?php echo $new->getTitle()?></td>
							<td><?php echo $new->getAuthor()?></td>
							<td><?php echo $new->getPublishDate()?></td>
							<td><a href="#" onclick="javascript:editNew(<?php echo $new->getId()?>);">修改</a></td>
							<td><a href="#" onclick="javascript:deleteNew(<?php echo $new->getId()?>);">删除</a></td>
						</tr>
						<?php
						} 
						?>
					</tbody>
				</table>
				</div>
				<div class="paging">
							<span><?php echo $page->getPageNo()."/".$page->getPageCount()?></span>
							<?php if ($page->getPageNo() > 1) {?>
								<span><a href="new_list.php?pageNo=1">首页</a></span>
								<span><a href="new_list.php?pageNo=<?php echo $page->getPageNo() - 1?>">上页</a></span>
							<?php }?>
							<?php
							for ($i = 1; $i <= $page->getPageCount(); $i++) {
								if ($i == $page->getPageNo()) {
							?>
									<span style="color:red;font-weight:bold;"><?php echo $i?></span>
							<?php
								} else {
							?>
									<span><a href="new_list.php?pageNo=<?php echo $i?>"><?php echo $i?></a></span>
							<?php
								}
							} 
							?>
							<?php if ($page->getPageNo() < $page->getPageCount()) {?>
								<span><a href="new_list.php?pageNo=<?php echo $page->getPageNo() + 1?>">下页</a></span>
								<span><a href="new_list.php?pageNo=<?php echo $page->getPageCount()?>">尾页</a></span>
							<?php }?>
				</div>
			</div>
		</div>
	</div>
	<?php include 'bottom.php';?>
</div>
</body>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('editor');
</script>
</html>